/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __WDT_FILE_H__
#define __WDT_FILE_H__

#include <vector>
#include "WowCommon.h"
#include "FileBase.h"

namespace PQGameCore
{
	/*
	Chunk
	WDT, ADT, WMO and WDL files follow a chunked structure similar to IFF, consisting of chunks of the following format:
	Offset  Type		Description
	0x0 	char [4] 	Chunk identifier - in reverse character order
	0x4 	uint32 		Chunk size
	0x8 	size*bytes 	Chunk data
	The initial chunk in all of these files is an MVER chunk, specifying the version of the files in a 32-bit integer.
	All files use Intel (little-endian) byte order.
	*/

	/*MPHD chunk
	Contains 8 32-bit integers.
	uint32 flags;
	uint32 something;
	uint32 unused[6];
	*/
	typedef struct _wdt_mphd{
		/*Flag 			Description
		0b0001 		No Terrain/no terraincollision. The other flags are ONLY for ADT based maps! See a list here.
		0b0010 		Use vertex shading (ADT.MCNK.MCCV)
		0b0100 		Decides whether to use _env terrain shaders or not: funky and if MCAL has 4096 instead of 2048(?)
		0b1000 		Disables something. No idea what. Another rendering thing. Someone may check all them in wild life..
		*/
		unsigned int flags;

		unsigned int sth;
		unsigned int unused[6];
	} wdt_mphd;

	/*0x00 	uint32 		ID (index in the MWMO list)
	0x04 	uint32 		unique identifier for this instance
	0x08 	3*floats 	Position (X,Y,Z)
	0x14 	3*floats 	Orientation (A,B,C)
	0x20 	6*floats 	Extents
	0x38 	uint32 		Flags
	0x3A 	uint16 		Doodad set index
	0x3C 	uint16 		Name set
	*/
	typedef struct _wdt_modf{
		int nameId;		
		int uniqueId;		
		float pos[3];		
		float rot[3]; 		
		float extents[6]; 		
		int flags;		
		short doodad_set;
		short nameSet;
	} wdt_modf;//Placement information for the WMO. 64 bytes

	class WdtFile
	{
	public:
		PQEngine::FileBase* _file;
		int version;//file version

		wdt_mphd *mphd;
		int map_tile_flag_table[64][64];
		int map_tile_async_obj_table[64][64];
		int modf_count;
		wdt_modf *modfs;
		std::vector<std::string> *wmo_filename_list;//equal to 0 when world with terrain
	public:
		~WdtFile(void);

		WdtFile();
		void init(PQEngine::FileBase *f);
	};
}

#endif
